function ssim = SSIM(x, y)
% ssim = SSIM(x,y)
% 
% SSIM performs the Structural Similarity Index (SSIM) for colour 
% images [1]. It is a wrapper function to ssim_index.m and averages the 
% SSIM value obtained for each channel. To use this function please download 
% ssim_index.m from [2]. For examples and suggested usagge see [2] as well.
%
% Note that the two images have to be given as a struct with colour values 
% in the range of [0 255].
%
% See also: PSNR
%
% [1] Z. Wang, A.C. Bovik, H.R. Sheikh, and E.P. Simoncelli, 
%     Image Quality Assessment: From Error Visibility to Structural Similarity,
%     IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, 2004
% [2] Z. Wang, A.C. Bovik, H.R. Sheikh, and E.P. Simoncelli,
%     The SSIM Index for Image Quality Assessment [online],
%     https://ece.uwaterloo.ca/~z70wang/research/ssim/#test, accessed Mar 2013
% 
% 2013-07-25 --------------------------------------------------------------
% 
% Matthias J. Ehrhardt
% CMIC, University College London, UK
% 
% matthias.ehrhardt.11@ucl.ac.uk
% 
% -------------------------------------------------------------------------
    
    X = Struct2im(x);
    Y = Struct2im(y);
    
    ssim = 1./3 * (ssim_index(X(:,:,1),Y(:,:,1)) ...
        + ssim_index(X(:,:,2),Y(:,:,2)) + ssim_index(X(:,:,3),Y(:,:,3)));
end